package com.imu.purse.mq.produce;

import com.alibaba.fastjson.JSON;
import com.imu.purse.modules.trade.form.TransForm;
import com.imu.purse.mq.config.RabbitUtil;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.support.CorrelationData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class YtfTransProduce {
    private static final String exchangeName = RabbitUtil.getValue("queue.ytf.trans.exchange");

    private String bitKey = RabbitUtil.getValue("queue.ytf.trans.key");

    private static final CorrelationData correlationData = new CorrelationData();
    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 发送消息到消息队列中
     * @param bean
     */
    public void sendData(TransForm bean){
        correlationData.setId(bean.getTransId());
        rabbitTemplate.convertAndSend(exchangeName, bitKey, JSON.toJSONString(bean),correlationData);
    }
}
